package mosync.mobilelualiveditor;

import javax.swing.JComponent;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class SliderController extends PropertyController
{
	public SliderController(String name)
	{
		super(name);
	}

	public String getCallbackTemplateHeader(String name)
	{
		return "function " + name + "_valueChanged(value)";
	}

	public JComponent createComponent()
	{
		JSlider slider = new JSlider();

		// slider.setMaximumSize(new Dimension(5000, 32));
		slider.addChangeListener(new ChangeListener()
		{
			public void stateChanged(ChangeEvent e)
			{
				JSlider slider = (JSlider) e.getSource();
				String value = "" + ((double) slider.getValue() / 100.0);
				String code = mName + "_valueChanged(" + value + ")\n";
				Evaluator.getSingleton().evaluate(code);
			}
		});

		return slider;
	}
}
